from app import create_app, db
from app.models import User, Post, Category

app = create_app()
app.app_context().push()

db.create_all()

# 添加示例数据
admin = User(username='admin', email='admin@example.com')
# 密码为admin
admin.password_hash = 'scrypt:32768:8:1$1ZnYHzKDtAwtNKvI$84b6e8c0f2268101228ac7b2991f847441061e57d877c057c5cb7d09ab6b26359737c28e6f3cb402790991dcf4353b14736e6128620e557511d42e898cd56b5a'  # 实际应用中应该使用generate_password_hash

db.session.add(admin)

categories = ['Python', 'Flask', 'Web开发']
for name in categories:
    cat = Category(name=name)
    db.session.add(cat)

post = Post(title='我的第一篇文章', content='这是我的第一篇博客文章内容...', author=admin)
post.categories.append(Category.query.filter_by(name='Python').first())

db.session.add(post)
db.session.commit()

print("数据库初始化完成！")